<?php 

function get_front_pages() // get the front pages from the database
{
	global $wpdb;
	$display_fpm_query = 'SELECT * FROM `'.$wpdb->prefix.'lazar_front_pages` ORDER BY ID';
	$display_fpm = $wpdb->get_results($display_fpm_query);
	return $display_fpm;
}


function create_wordpress_admin_front_page_submenu()
{
	add_submenu_page( 'my-top-level-handle', 'Front page Options', 'Front Page Options', 'manage_options', 'my-submenu-front-page-handle', 'front_page_admin_page');
	add_action('admin_init', 'register_front_page_settings');
}

function register_front_page_settings()
{ 
	
}
	
function front_page_admin_page() {

	function create_tables($table_name)
	{
		global $wpdb;
		
		if ($table_name == $wpdb->prefix.'lazar_front_pages')
		{
			$create_query = 'CREATE TABLE `'.$wpdb->prefix.'lazar_front_pages` (
								`id` INT NOT NULL AUTO_INCREMENT ,
								`name` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
								`description` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
								PRIMARY KEY (`id`)
							) ENGINE = MYISAM ;
								';
			$create = $wpdb->get_results($create_query);
		}
		
		if ($table_name == $wpdb->prefix.'lazar_fp_elements')
		{
			$create_query = 'CREATE TABLE `'.$wpdb->prefix.'lazar_fp_elements` (
								`id` INT NOT NULL AUTO_INCREMENT ,
								`order` INT NOT NULL ,
								`parent_id` INT NOT NULL,
								`type` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
								`active` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
								PRIMARY KEY (`id`)
							) ENGINE = MYISAM ;
								';
			$create = $wpdb->get_results($create_query);
		}
	}

	//CHECK FUNCTION
	function check_if_the_table_exists($the_table_name)
	{
		global $wpdb;
		if($wpdb->get_var("SHOW TABLES LIKE '".$the_table_name."'") != $the_table_name)
			return '';
		
		else 
			return 'table_exists';
	}

	global $wpdb;
	if ( check_if_the_table_exists($wpdb->prefix.'lazar_front_pages') == '') create_tables($wpdb->prefix.'lazar_front_pages');
	if ( check_if_the_table_exists($wpdb->prefix.'lazar_fp_elements') == '') create_tables($wpdb->prefix.'lazar_fp_elements');
	
	function get_fp_elements($id) // get the front page elements from the database
	{
		global $wpdb;
		$display_fp_elements_query = "SELECT * FROM `".$wpdb->prefix."lazar_fp_elements` WHERE `parent_id` = '$id' ORDER BY `order`";
		$display_fp_elements = $wpdb->get_results($display_fp_elements_query);
		return $display_fp_elements;
	}
	
	function insert_in_front_pages($id, $name, $description)
	{
		global $wpdb;
		$insert_query = "INSERT INTO `".$wpdb->prefix."lazar_front_pages` (`id`, `name`, `description`) VALUES ('".$id."', '".$name."', '".$description."');";
		$insert = $wpdb->get_results($insert_query);
		$insert_id = $wpdb->insert_id;
		
		$position_counter = 0;
		for ($i = 0; $i < 11; $i++)
		{
			if ($i == 0) $type = 'intro';
			if ($i == 1) $type = 'posts';
			if ($i == 2) $type = 'features';
			if ($i == 3) $type = 'blog';
			if ($i == 4) $type = 'slideshow';
			if ($i == 5) $type = 'news';
			if ($i == 6) $type = 'tabs';
			if ($i == 7) $type = 'testimonials';
			if ($i == 8) $type = 'contact';
			if ($i == 9) $type = 'custom';
			if ($i == 10) $type = 'the_content';
			insert_in_fp_elements(NULL, $i, $insert_id, $type, '0');
		}
		$refer = $_SERVER['HTTP_REFERER'];
		
		echo "<script language=\"JavaScript\">
        <!--
        document.location.href  = \"".$refer."\";
        -->
        </script>";
	}
	
	function insert_in_fp_elements($id, $order, $parent_id, $type, $active)
	{
		global $wpdb;
		$insert_query = "INSERT INTO `".$wpdb->prefix."lazar_fp_elements` (`id`, `order`, `parent_id`, `type`, `active`) VALUES ('".$id."', '".$order."', '".$parent_id."', '".$type."', '".$active."');";

		switch($type)
		{
			case 'intro':
				update_option( 'enable_intro_'.$parent_id, '' );
				update_option( 'first_message_'.$parent_id, '' );
				update_option( 'second_message_'.$parent_id, '' );
				update_option( 'button_text_'.$parent_id, '' );
				update_option( 'button_url_'.$parent_id, '' );
			break;
			
			case 'posts': 
				update_option( 'enable_posts_'.$parent_id, 'yes' );
				update_option( 'post_categories_'.$parent_id, '' );
				update_option( 'posts_count_'.$parent_id, '3' );
			break;
			
			case 'features':
				update_option( 'enable_features_'.$parent_id, 'no' );
				update_option( 'features_font_size_'.$parent_id, '20' );
				update_option( 'feature_1_icon_'.$parent_id, '' );
				update_option( 'feature_1_text_'.$parent_id, '' );
				update_option( 'feature_1_link_'.$parent_id, '' );
				update_option( 'feature_2_icon_'.$parent_id, '' );
				update_option( 'feature_2_text_'.$parent_id, '' );
				update_option( 'feature_2_link_'.$parent_id, '' );
				update_option( 'feature_3_icon_'.$parent_id, '' );
				update_option( 'feature_3_text_'.$parent_id, '' );
				update_option( 'feature_3_link_'.$parent_id, '' );
				update_option( 'feature_4_icon_'.$parent_id, '' );
				update_option( 'feature_4_text_'.$parent_id, '' );
				update_option( 'feature_4_link_'.$parent_id, '' );
				update_option( 'feature_5_icon_'.$parent_id, '' );
				update_option( 'feature_5_text_'.$parent_id, '' );
				update_option( 'feature_5_link_'.$parent_id, '' );
				update_option( 'feature_6_icon_'.$parent_id, '' );
				update_option( 'feature_6_text_'.$parent_id, '' );
				update_option( 'feature_6_link_'.$parent_id, '' );
			break;
			
			case 'blog':
				update_option( 'enable_blog_'.$parent_id, 'yes' );
				update_option( 'blog_width_'.$parent_id, '0.5' );
				update_option( 'blog_heading_'.$parent_id, '' );
				update_option( 'blog_categories_'.$parent_id, '' );
				update_option( 'blog_elements_per_row_'.$parent_id, '4' );
				update_option( 'blog_count_'.$parent_id, '3' );
			break;	
			
			case 'slideshow':
				update_option( 'enable_slideshow_'.$parent_id, 'yes' );
				update_option( 'slideshow_width_'.$parent_id, '0.5' );
				update_option( 'slideshow_height_'.$parent_id, '250' );
				update_option( 'slideshow_heading_'.$parent_id, '' );
				update_option( 'slideshow_description_'.$parent_id, '' );
				update_option( 'slideshow_transitions_'.$parent_id, 'random' );
				update_option( 'slideshow_pausetime_'.$parent_id, '10000' );
				update_option( 'slideshow_categories_'.$parent_id, '' );
				update_option( 'slideshow_count_'.$parent_id, '3' );
			break;
			
			case 'news':
				update_option( 'enable_news_'.$parent_id, 'yes' );
				update_option( 'news_width_'.$parent_id, '0.5' );
				update_option( 'news_heading_'.$parent_id, '' );
				update_option( 'news_categories_'.$parent_id, '' );
				update_option( 'news_count_'.$parent_id, '3' );
			break;
			
			case 'tabs':
				update_option( 'enable_tabs_'.$parent_id, 'yes' );
				update_option( 'tabs_width_'.$parent_id, '0.5' );
				update_option( 'tabs_heading_'.$parent_id, '' );
				update_option( 'tab_1_title_'.$parent_id, '' );
				update_option( 'tab_1_content_'.$parent_id, '' );
				update_option( 'tab_2_title_'.$parent_id, '' );
				update_option( 'tab_2_content_'.$parent_id, '' );
				update_option( 'tab_3_title_'.$parent_id, '' );
				update_option( 'tab_3_content_'.$parent_id, '' );
				update_option( 'tab_4_title_'.$parent_id, '' );
				update_option( 'tab_4_content_'.$parent_id, '' );
			break;
			
			case 'testimonials':
				update_option( 'enable_testimonials_'.$parent_id, 'no' );
				update_option( 'testimonials_width_'.$parent_id, '1' );
				update_option( 'testimonials_heading_'.$parent_id, '' );
				update_option( 'testimonial_1_text_'.$parent_id, '' );
				update_option( 'testimonial_1_person_'.$parent_id, '' );
				update_option( 'testimonial_1_link_'.$parent_id, '' );
				update_option( 'testimonial_2_text_'.$parent_id, '' );
				update_option( 'testimonial_2_person_'.$parent_id, '' );
				update_option( 'testimonial_2_link_'.$parent_id, '' );
				update_option( 'testimonial_3_text_'.$parent_id, '' );
				update_option( 'testimonial_3_person_'.$parent_id, '' );
				update_option( 'testimonial_3_link_'.$parent_id, '' );
			break;
			
			case 'contact':
				update_option( 'enable_contact_'.$parent_id, 'no' );
				update_option( 'contact_heading_'.$parent_id, '' );
				update_option( 'enable_recaptcha_'.$parent_id, 'no' );
			break;
			
			case 'custom':
				update_option( 'enable_custom_'.$parent_id, 'yes' );
				update_option( 'custom_width_'.$parent_id, '0.5' );
				update_option( 'custom_heading_'.$parent_id, '' );
				update_option( 'custom_content_'.$parent_id, '' );
			break;
			
			case 'the_content':
				update_option( 'enable_the_content_'.$parent_id, 'no' );
				update_option( 'display_the_content_title_'.$parent_id, 'no' );
				update_option( 'the_content_width_'.$parent_id, '0.5' );
			break;
				
		}
		$insert = $wpdb->get_results($insert_query);	
	}
	
	function delete_front_page($id)
	{
		global $wpdb;

		// Intro:
		delete_option( 'enable_intro_'.$id );
		delete_option( 'first_message_'.$id );
		delete_option( 'second_message_'.$id );
		delete_option( 'button_text_'.$id );
		delete_option( 'button_url_'.$id );
		
		// Posts:
		delete_option( 'enable_posts_'.$id );
		delete_option( 'post_categories_'.$id );
		delete_option( 'posts_count_'.$id );
		
		// Features:
		delete_option( 'enable_features_'.$id );
		delete_option( 'features_font_size_'.$id );
		delete_option( 'feature_1_icon_'.$id );
		delete_option( 'feature_1_text_'.$id );
		delete_option( 'feature_1_link_'.$id );
		delete_option( 'feature_2_icon_'.$id );
		delete_option( 'feature_2_text_'.$id );
		delete_option( 'feature_2_link_'.$id );
		delete_option( 'feature_3_icon_'.$id );
		delete_option( 'feature_3_text_'.$id );
		delete_option( 'feature_3_link_'.$id );
		delete_option( 'feature_4_icon_'.$id );
		delete_option( 'feature_4_text_'.$id );
		delete_option( 'feature_4_link_'.$id );
		delete_option( 'feature_5_icon_'.$id );
		delete_option( 'feature_5_text_'.$id );
		delete_option( 'feature_5_link_'.$id );
		delete_option( 'feature_6_icon_'.$id );
		delete_option( 'feature_6_text_'.$id );
		delete_option( 'feature_6_link_'.$id );
		
		// Blog:
		delete_option( 'enable_blog_'.$id );
		delete_option( 'blog_width_'.$id );
		delete_option( 'blog_heading_'.$id );
		delete_option( 'blog_categories_'.$id );
		delete_option( 'blog_elements_per_row_'.$id );
		delete_option( 'blog_count_'.$id );
		
		// Slideshow:
		delete_option( 'enable_slideshow_'.$id );
		delete_option( 'slideshow_width_'.$id );
		delete_option( 'slideshow_height_'.$id );
		delete_option( 'slideshow_heading_'.$id );
		delete_option( 'slideshow_description_'.$id );
		delete_option( 'slideshow_transitions_'.$id );
		delete_option( 'slideshow_pausetime_'.$id );
		delete_option( 'slideshow_categories_'.$id );
		delete_option( 'slideshow_count_'.$id );
		
		// News:
		delete_option( 'enable_news_'.$id );
		delete_option( 'news_width_'.$id );
		delete_option( 'news_heading_'.$id );
		delete_option( 'news_categories_'.$id );
		delete_option( 'news_count_'.$id );
		
		// Tabs:
		delete_option( 'enable_tabs_'.$id );
		delete_option( 'tabs_width_'.$id );
		delete_option( 'tabs_heading_'.$id );
		delete_option( 'tab_1_title_'.$id );
		delete_option( 'tab_1_content_'.$id );
		delete_option( 'tab_2_title_'.$id );
		delete_option( 'tab_2_content_'.$id );
		delete_option( 'tab_3_title_'.$id );
		delete_option( 'tab_3_content_'.$id );
		delete_option( 'tab_4_title_'.$id );
		delete_option( 'tab_4_content_'.$id );
		
		// Testimonials:
		delete_option( 'enable_testimonials_'.$id );
		delete_option( 'testimonials_width_'.$id );
		delete_option( 'testimonials_heading_'.$id );
		delete_option( 'testimonial_1_text_'.$id );
		delete_option( 'testimonial_1_person_'.$id );
		delete_option( 'testimonial_1_link_'.$id );
		delete_option( 'testimonial_2_text_'.$id );
		delete_option( 'testimonial_2_person_'.$id );
		delete_option( 'testimonial_2_link_'.$id );
		delete_option( 'testimonial_3_text_'.$id );
		delete_option( 'testimonial_3_person_'.$id );
		delete_option( 'testimonial_3_link_'.$id );
		
		// Contact:
		delete_option( 'enable_contact_'.$id );
		delete_option( 'contact_heading_'.$id );
		delete_option( 'enable_recaptcha_'.$id );
		
		// Custom:
		delete_option( 'enable_custom_'.$id );
		delete_option( 'custom_heading_'.$id );
		delete_option( 'custom_content_'.$id );
		
		// The Content (page content):
		delete_option( 'enable_the_content_'.$id );
		delete_option( 'display_the_content_title_'.$id );
		delete_option( 'the_content_width_'.$id );
		
		
		$delete_query = 'DELETE FROM `'.$wpdb->prefix.'lazar_fp_elements` WHERE parent_id = '.$id.' LIMIT 7';
		
		$delete_query = 'DELETE FROM `'.$wpdb->prefix.'lazar_front_pages` WHERE id = '.$id.' LIMIT 1';
		$wpdb->get_results($delete_query);
		
		$refer = $_SERVER['HTTP_REFERER'];
		
		echo "<script language=\"JavaScript\">
        <!--
        document.location.href  = \"".$refer."\";
        -->
        </script>";
	}
	
	function display_entry($type, $id)
	{
		global $wpdb;
		$query = "SELECT * FROM $wpdb->posts WHERE post_type = '".$type."' AND ID ='".$id."' ";
		$result = $wpdb->get_results($query);
		return $result;
	}
	
	function display_entry_children($type, $id)
	{
		global $wpdb;
		$query = "SELECT * FROM $wpdb->posts WHERE post_parent = '".$id."' AND post_type = 'attachment' ";
		$result = $wpdb->get_results($query);
		return $result;
	}
	
	if ( get_option('database_action') == 'create' )
	{
		$type = get_option('element_type');
		if($type == 'page') $value = get_option('which_page');
		if($type == 'post') $value = get_option('which_post');
		insert_in_db(NULL, $type, $value);
		update_option('database_action','');
	}
	
	function front_page_update($id)
	{
		// Intro:
		update_option( 'enable_intro_'.$id, $_POST['enable_intro'] );
		update_option( 'first_message_'.$id, stripslashes($_POST['first_message']) );
		update_option( 'second_message_'.$id, stripslashes($_POST['second_message']) );
		update_option( 'button_text_'.$id, stripslashes($_POST['button_text']) );
		update_option( 'button_url_'.$id, $_POST['button_url'] );
		
		// Posts:
		update_option( 'enable_posts_'.$id, $_POST['enable_posts'] );
		if ( isset($_POST['post_categories']) ) $post_categories = implode(',',$_POST['post_categories']);
		else $post_categories = '';	
		update_option( 'post_categories_'.$id, $post_categories );
		update_option( 'posts_count_'.$id, $_POST['posts_count'] );
		
		// Features:
		update_option( 'enable_features_'.$id, $_POST['enable_features'] );
		update_option( 'features_font_size_'.$id, $_POST['features_font_size'] );
		update_option( 'feature_1_icon_'.$id, stripslashes($_POST['feature_1_icon']) );
		update_option( 'feature_1_text_'.$id, stripslashes($_POST['feature_1_text']) );
		update_option( 'feature_1_link_'.$id, stripslashes($_POST['feature_1_link']) );
		update_option( 'feature_2_icon_'.$id, stripslashes($_POST['feature_2_icon']) );
		update_option( 'feature_2_text_'.$id, stripslashes($_POST['feature_2_text']) );
		update_option( 'feature_2_link_'.$id, stripslashes($_POST['feature_2_link']) );
		update_option( 'feature_3_icon_'.$id, stripslashes($_POST['feature_3_icon']) );
		update_option( 'feature_3_text_'.$id, stripslashes($_POST['feature_3_text']) );
		update_option( 'feature_3_link_'.$id, stripslashes($_POST['feature_3_link']) );
		update_option( 'feature_4_icon_'.$id, stripslashes($_POST['feature_4_icon']) );
		update_option( 'feature_4_text_'.$id, stripslashes($_POST['feature_4_text']) );
		update_option( 'feature_4_link_'.$id, stripslashes($_POST['feature_4_link']) );
		update_option( 'feature_5_icon_'.$id, stripslashes($_POST['feature_5_icon']) );
		update_option( 'feature_5_text_'.$id, stripslashes($_POST['feature_5_text']) );
		update_option( 'feature_5_link_'.$id, stripslashes($_POST['feature_5_link']) );
		update_option( 'feature_6_icon_'.$id, stripslashes($_POST['feature_6_icon']) );
		update_option( 'feature_6_text_'.$id, stripslashes($_POST['feature_6_text']) );
		update_option( 'feature_6_link_'.$id, stripslashes($_POST['feature_6_link']) );
		
		// Blog:
		update_option( 'enable_blog_'.$id, $_POST['enable_blog'] );
		update_option( 'blog_width_'.$id, $_POST['blog_width'] );
		update_option( 'blog_heading_'.$id, stripslashes($_POST['blog_heading']) );
		if ( isset($_POST['blog_categories']) ) $blog_categories = implode(',',$_POST['blog_categories']);
		else $blog_categories = '';	
		update_option( 'blog_categories_'.$id, $blog_categories );
		update_option( 'blog_elements_per_row_'.$id, $_POST['blog_elements_per_row'] );
		update_option( 'blog_count_'.$id, $_POST['blog_count'] );
		
		// Slideshow: 
		update_option( 'enable_slideshow_'.$id, $_POST['enable_slideshow'] );
		update_option( 'slideshow_width_'.$id, $_POST['slideshow_width'] );
		update_option( 'slideshow_height_'.$id, $_POST['slideshow_height'] );
		update_option( 'slideshow_heading_'.$id, stripslashes($_POST['slideshow_heading']) );
		update_option( 'slideshow_description_'.$id, stripslashes($_POST['slideshow_description']) );
		update_option( 'slideshow_transitions_'.$id, stripslashes($_POST['slideshow_transitions']) );
		update_option( 'slideshow_pausetime_'.$id, stripslashes($_POST['slideshow_pausetime']) );
		if ( isset($_POST['slideshow_categories']) ) $slideshow_categories = implode(',',$_POST['slideshow_categories']);
		else $slideshow_categories = '';	
		update_option( 'slideshow_categories_'.$id, $slideshow_categories );
		update_option( 'slideshow_count_'.$id, $_POST['slideshow_count'] );
		
		// News:
		update_option( 'enable_news_'.$id, $_POST['enable_news'] );
		update_option( 'news_width_'.$id, $_POST['news_width'] );
		update_option( 'news_heading_'.$id, stripslashes($_POST['news_heading']) );
		if ( isset($_POST['news_categories']) ) $news_categories = implode(',',$_POST['news_categories']);
		else $news_categories = '';	
		update_option( 'news_categories_'.$id, $news_categories );
		update_option( 'news_count_'.$id, $_POST['news_count'] );

		// Tabs:
		update_option( 'enable_tabs_'.$id, $_POST['enable_tabs'] );
		update_option( 'tabs_width_'.$id, $_POST['tabs_width'] );
		update_option( 'tabs_heading_'.$id, stripslashes($_POST['tabs_heading']) );
		update_option( 'tab_1_title_'.$id, stripslashes($_POST['tab_1_title']) );
		update_option( 'tab_1_content_'.$id, stripslashes($_POST['tab_1_content']) );
		update_option( 'tab_2_title_'.$id, stripslashes($_POST['tab_2_title']) );
		update_option( 'tab_2_content_'.$id, stripslashes($_POST['tab_2_content']) );
		update_option( 'tab_3_title_'.$id, stripslashes($_POST['tab_3_title']) );
		update_option( 'tab_3_content_'.$id, stripslashes($_POST['tab_3_content']) );
		update_option( 'tab_4_title_'.$id, stripslashes($_POST['tab_4_title']) );
		update_option( 'tab_4_content_'.$id, stripslashes($_POST['tab_4_content']) );
		
		// Testimonials:
		update_option( 'enable_testimonials_'.$id, $_POST['enable_testimonials'] );
		update_option( 'testimonials_width_'.$id, $_POST['testimonials_width'] );
		update_option( 'testimonials_heading_'.$id, stripslashes($_POST['testimonials_heading']) );
		update_option( 'testimonial_1_text_'.$id, stripslashes($_POST['testimonial_1_text']) );
		update_option( 'testimonial_1_person_'.$id, stripslashes($_POST['testimonial_1_person']) );
		update_option( 'testimonial_1_link_'.$id, stripslashes($_POST['testimonial_1_link']) );
		update_option( 'testimonial_2_text_'.$id, stripslashes($_POST['testimonial_2_text']) );
		update_option( 'testimonial_2_person_'.$id, stripslashes($_POST['testimonial_2_person']) );
		update_option( 'testimonial_2_link_'.$id, stripslashes($_POST['testimonial_2_link']) );
		update_option( 'testimonial_3_text_'.$id, stripslashes($_POST['testimonial_3_text']) );
		update_option( 'testimonial_3_person_'.$id, stripslashes($_POST['testimonial_3_person']) );
		update_option( 'testimonial_3_link_'.$id, stripslashes($_POST['testimonial_3_link']) );
		
		// Contact:
		update_option( 'enable_contact_'.$id, $_POST['enable_contact'] );
		update_option( 'contact_heading_'.$id, stripslashes($_POST['contact_heading']) );
		update_option( 'enable_recaptcha_'.$id, $_POST['enable_recaptcha'] );
		
		// Custom:
		update_option( 'enable_custom_'.$id, $_POST['enable_custom'] );
		update_option( 'custom_width_'.$id, $_POST['custom_width'] );
		update_option( 'custom_heading_'.$id, stripslashes($_POST['custom_heading']) );
		update_option( 'custom_content_'.$id, stripslashes($_POST['custom_content']) );
		
		// The Content (page content):
		update_option( 'enable_the_content_'.$id, $_POST['enable_the_content'] );
		update_option( 'display_the_content_title_'.$id, $_POST['display_the_content_title'] );
		update_option( 'the_content_width_'.$id, $_POST['the_content_width'] );

	}
	
	if(isset($_GET['delete']))
		if($_GET['delete'] != '') delete_front_page($_GET['delete']); // IF CALLED DELETES A SLIDE BY ID 
	
	if (isset($_POST['front_page_name']) && $_POST['front_page_name'] != '')
	{
		insert_in_front_pages(NULL, $_POST['front_page_name'], $_POST['front_page_description']);
	}

	if ( get_option('sidebar_active') == '' ) update_option('sidebar_active','yes');
	if ( get_option('sidebar_position') == '' ) update_option('sidebar_position','right');
	if ( get_option('number_of_columns_with_sidebar') == '' ) update_option('number_of_columns_with_sidebar','2_columns');
	if ( get_option('number_of_columns_no_sidebar') == '' ) update_option('number_of_columns_no_sidebar','3_columns');

	?>

	<script type="text/javascript" language="javascript">
		/* function for confirming you want to delete */
		function confirmAction()
		{
			return confirm("Are you sure you want to delete this frontpage?")
		}
		
		jQuery(document).ready(function() {
			jQuery('.header').click(function() {
				jQuery(this).next('.hidden_content').stop(true, true).toggle('fast');
			});
		});
	</script> 

<div class="wrap">  
	<div id="icon-options-general" class="icon32"><br /></div>
	<h2>Front Page Options</h2>
    
     <?php
	$get_admin_warnings = admin_warnings();
	if ( $get_admin_warnings != '' )
	{
		echo '<div id="admin_warnings">';
			echo '<div id="admin_warning_icon"></div>';
			echo $get_admin_warnings;
		echo '</div>';
	}
	
		
			$display_front_pages = get_front_pages();
			
			$front_page_id_list = array();
			$front_page_name_list = array();
			
			echo '
				<script type="text/javascript">
					jQuery(document).ready(function() {
						jQuery("#front_page_tabs").tabs();
						jQuery(".transform").jqTransform();
					});
				</script>
				';
			
			echo '<div id="front_page_tabs" class="admin_tabs">';
				echo '<ul>';
					echo '<li>';
						echo '<a href="#tab_pages">';
							echo '<span>Current Pages</span>';
						echo '</a>';
					echo '</li>';
					
					echo '<li>';
						echo '<a href="#tab_add_page">';
							echo '<span>Add Frontpage</span>';
						echo '</a>';
					echo '</li>';
						
					foreach ($display_front_pages as $key => $front_page)
					{
						array_push($front_page_id_list, $front_page->id);
						array_push($front_page_name_list, $front_page->name);
						
						echo '<li>';
							echo '<a href="#tab_'.$key.'">';
								echo '<span>'.$front_page->name.'</span>';
							echo '</a>';
						echo '</li>';
					}
		
				echo' </ul>';

				echo '<div id="tab_pages">';
				if (empty($display_front_pages) != '1')
				{
				?>
					<table id="sort_slider" class="display_elements" cellspacing="0">
						<thead>
							<tr>
								<th class="title">Title</th>
								<th class="title">Description</th>
								<th>Delete</th>     
							</tr>           
						</thead>
                        
                        <tbody>
                        <?php
						$i = 0;
						foreach ($display_front_pages as $key => $front_page)
						{
							if ($i == 0) echo '<tr class="alternate" valign="top">';
							else echo '<tr>';
								echo '<td>';
									echo $front_page->name;
								echo '</td>';
								echo '<td>';
									echo $front_page->description;
								echo '</td>';
								echo '<td valign="center" align="center">';
									echo '<a class="delete" onClick="return confirmAction()" href="?page=my-submenu-front-page-handle&amp;delete='.$front_page->id.'">Delete</a>';
								echo '</td>';
							echo '</tr>';
							
							$i++;
							if ($i == 2) $i = 0;
						} // END foreach ($display_front_pages as $key => $front_page)
						?>
                        </tbody>
                        <tfoot>
							<tr>
								<th>Title</th>
								<th>Description</th>
								<th>Delete</th>
							</tr>           
						</tfoot>
						
					</table>   
                <?php 
				} // END if ($display_front_pages != '')
				
				else 
				{
					echo '<div id="admin_warnings">';
						echo 'There are no Front Pages';
					echo '</div>';
				}
				
				echo '</div>'; // end <div id="tab_pages">
				
				
				echo '<div id="tab_add_page">';
					echo '<form method="post" action="'; echo home_url(); echo '/wp-admin/admin.php?page=my-submenu-front-page-handle" >';
						echo '<div class="settings_wrapper">';
							echo '<div class="header">';
								echo 'Add Front Page';
							echo '</div>';
							echo '<div class="row_data">';
								echo '<div class="row clearfix alternate">';
									echo '<label>Name:</label>';
									echo '<input class="input_box" type="text" name="front_page_name" value="" />';
								echo '</div>';
								echo '<div class="row clearfix">';
									echo '<label>Description:</label>';
									echo '<input class="input_box" type="text" name="front_page_description" value="" />';
								echo '</div>';
								echo '<div class="row clearfix alternate">';
									echo '<input class="add_content_button" type="submit" value="Add Front Page" name="Submit">';
								echo '</div>';
							echo '</div>';
						echo '</div>';
					echo '</form>';
				echo '</div>';

		if ( isset($_POST['front_page_update']) && $_POST['front_page_update'] == 'true') { front_page_update($_POST['front_page']); }

				

				foreach ($front_page_id_list as $key => $front_page_id)
				{
					?>
					
					<script type="text/javascript">
					
					jQuery(document).ready(function() {
					   jQuery("#<?php echo 'elements_'.$key; ?>").sortable({
						  handle : '.element_move',
						  placeholder: 'ui-state-highlight',
						  items: 'li:not(.ui-state-disabled)',
						 // axis: 'y',
						  update : function () {
							  //var order = $('#test-list').sortable('serialize');
							  var order = '';
							  jQuery("#<?php echo 'elements_'.$key; ?> li").each(function(index) {		
										order += jQuery(this).attr('id') + ',' ;												  
									});
							  
							  order = 'order=' + order;
							  <?php $reorder_path = get_template_directory_uri().'/theme_options/front_pages_reorder.php'; 
							  echo '
							  jQuery.get("'.$reorder_path.'", order, function(theResponse){
										jQuery("#show_here").html(theResponse);
									});
							  ';
							  ?>
							  
							//$("#info").load("process-sortable.php?"+order);
						  }
						});
					   
					});
					</script>
					
	
					<?php

					echo '<div id="tab_'.$key.'">';
						echo '<form method="post" class="transform" action="#tab_'.$key.'" class="transform">';
						
							echo '<input type="hidden" name="front_page_update" value="true" />';
							echo '<input type="hidden" name="front_page" value="'.$front_page_id.'" />';
						
							echo '<ul id="elements_'.$key.'" class="front_page_elements">';
							
							$display_fp_elements = get_fp_elements($front_page_id);
							
							foreach ($display_fp_elements as $fp_element)
							{
								echo '<li class="settings_wrapper'; /*if ($fp_element->type == 'intro') echo ' ui-state-disabled';*/ echo '" id="'.$fp_element->id.'">';
									echo '<div class="header">';
										switch ($fp_element->type)
										{
											case 'intro': echo 'Intro Paragraph'; break;
											
											case 'posts': echo 'Posts'; break;
											
											case 'features': echo 'Features'; break;
											
											case 'blog': echo 'Blog'; break;
											
											case 'slideshow': echo 'Slideshow'; break;
											
											case 'news': echo 'Latest news'; break;
											
											case 'tabs': echo 'Tabs'; break;
											
											case 'testimonials': echo 'Testimonials'; break;
											
											case 'contact': echo 'Contact Form'; break;
											
											case 'custom': echo 'Custom Element'; break;
											
											case 'the_content': echo 'The Page Content'; break;
										}

										echo '<div class="element_move"></div>';
									echo '</div>';
									
									echo '<div class="row_data hidden_content">';
									
									switch($fp_element->type)
									{
										case 'intro':
											$enable_intro = get_option( 'enable_intro_'.$fp_element->parent_id );
											echo '<div class="row clearfix alternate">';
												echo '<label>Enable Intro</label>';
												echo '<select name="enable_intro">';
													echo '<option value="yes"'; if ($enable_intro == 'yes') echo ' selected="selected"'; echo '>Yes</option>';
													echo '<option value="no"'; if ($enable_intro == 'no') echo ' selected="selected"'; echo '>No</option>';
												echo '</select>';
											echo '</div>';
											
											echo '<div class="row clearfix">';
												echo '<label>First Message</label>';
												echo '<input type="text" name="first_message" class="input_box" value="'.get_option( 'first_message_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Second Message</label>';
												echo '<input type="text" name="second_message" class="input_box" value="'.get_option( 'second_message_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix">';
												echo '<label>Button Text</label>';
												echo '<input type="text" name="button_text" class="input_box" value="'.get_option( 'button_text_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											echo '<div class="row clearfix alternate">';
												echo '<label>Button URL</label>';
												echo '<input type="text" name="button_url" class="input_box" value="'.get_option( 'button_url_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
										break; // END case 'intro'
										
										case 'posts': 
											$enable_posts = get_option( 'enable_posts_'.$fp_element->parent_id );
											echo '<div class="row clearfix alternate">';
												echo '<label>Enable Posts</label>';
												echo '<select name="enable_posts">';
													echo '<option value="yes"'; if ($enable_posts == 'yes') echo ' selected="selected"'; echo '>Yes</option>';
													echo '<option value="no"'; if ($enable_posts == 'no') echo ' selected="selected"'; echo '>No</option>';
												echo '</select>';
											echo '</div>';
											
											$current_categories = explode(',', get_option( 'post_categories_'.$fp_element->parent_id ));
											$categories = get_categories();
											
											echo '<div class="row clearfix">';
												echo '<label>Posts Categories</label>';
												echo '<ul class="categories_listing">';								
													foreach ($categories as $category)
													{
														$validate = NULL;
														$checked = '';
														
														$haystack = array();
														$haystack[] = $category->cat_ID;
														
														foreach($current_categories as $current_category)
														{
															if ($current_category == $category->cat_ID)
															{
																$validate = true;
																break;
															}
														}

														if ( $validate != '' ) $checked = ' checked="checked"';
														echo '<li>';
															echo '<input id="post_'.$category->cat_ID.'" type="checkbox" name="post_categories[]" value="'.$category->cat_ID.'"'.$checked.' />';
															echo $category->name;
														echo '</li>';										
													}
												echo '</ul>';	
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Posts Count</label>';
												echo '<input type="text" name="posts_count" class="input_box" value="'.get_option( 'posts_count_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
										break; // END case 'posts'
										
										case 'features':
											$enable_features = get_option( 'enable_features_'.$fp_element->parent_id );
											echo '<div class="row clearfix alternate">';
												echo '<label>Enable Features</label>';
												echo '<select name="enable_features">';
													echo '<option value="yes"'; if ($enable_features == 'yes') echo ' selected="selected"'; echo '>Yes</option>';
													echo '<option value="no"'; if ($enable_features == 'no') echo ' selected="selected"'; echo '>No</option>';
												echo '</select>';
											echo '</div>';
											
											$features_font_size = get_option( 'features_font_size_'.$fp_element->parent_id );
											echo '<div class="row clearfix alternate">';
												echo '<label>Font Size (pt)</label>';
												echo '<select name="features_font_size">';
													echo '<option value="16"'; if ($features_font_size == '16') echo ' selected="selected"'; echo '>16</option>';
													echo '<option value="17"'; if ($features_font_size == '17') echo ' selected="selected"'; echo '>17</option>';
													echo '<option value="18"'; if ($features_font_size == '18') echo ' selected="selected"'; echo '>18</option>';
													echo '<option value="19"'; if ($features_font_size == '19') echo ' selected="selected"'; echo '>19</option>';
													echo '<option value="20"'; if ($features_font_size == '20') echo ' selected="selected"'; echo '>20</option>';
												echo '</select>';
											echo '</div>';
											
											echo '<div class="row clearfix">';
												echo '<label>Feature 1 Icon</label>';
												echo '<input type="text" name="feature_1_icon" class="input_box" value="'.get_option( 'feature_1_icon_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Feature 1 Text</label>';
												echo '<input type="text" name="feature_1_text" class="input_box" value="'.get_option( 'feature_1_text_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix">';
												echo '<label>Feature 1 Link</label>';
												echo '<input type="text" name="feature_1_link" class="input_box" value="'.get_option( 'feature_1_link_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Feature 2 Icon</label>';
												echo '<input type="text" name="feature_2_icon" class="input_box" value="'.get_option( 'feature_2_icon_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix">';
												echo '<label>Feature 2 Text</label>';
												echo '<input type="text" name="feature_2_text" class="input_box" value="'.get_option( 'feature_2_text_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Feature 2 Link</label>';
												echo '<input type="text" name="feature_2_link" class="input_box" value="'.get_option( 'feature_2_link_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix">';
												echo '<label>Feature 3 Icon</label>';
												echo '<input type="text" name="feature_3_icon" class="input_box" value="'.get_option( 'feature_3_icon_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Feature 3 Text</label>';
												echo '<input type="text" name="feature_3_text" class="input_box" value="'.get_option( 'feature_3_text_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix">';
												echo '<label>Feature 3 Link</label>';
												echo '<input type="text" name="feature_3_link" class="input_box" value="'.get_option( 'feature_3_link_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Feature 4 Icon</label>';
												echo '<input type="text" name="feature_4_icon" class="input_box" value="'.get_option( 'feature_4_icon_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix">';
												echo '<label>Feature 4 Text</label>';
												echo '<input type="text" name="feature_4_text" class="input_box" value="'.get_option( 'feature_4_text_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Feature 4 Link</label>';
												echo '<input type="text" name="feature_4_link" class="input_box" value="'.get_option( 'feature_4_link_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix">';
												echo '<label>Feature 5 Icon</label>';
												echo '<input type="text" name="feature_5_icon" class="input_box" value="'.get_option( 'feature_5_icon_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Feature 5 Text</label>';
												echo '<input type="text" name="feature_5_text" class="input_box" value="'.get_option( 'feature_5_text_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix">';
												echo '<label>Feature 5 Link</label>';
												echo '<input type="text" name="feature_5_link" class="input_box" value="'.get_option( 'feature_5_link_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Feature 6 Icon</label>';
												echo '<input type="text" name="feature_6_icon" class="input_box" value="'.get_option( 'feature_6_icon_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix">';
												echo '<label>Feature 6 Text</label>';
												echo '<input type="text" name="feature_6_text" class="input_box" value="'.get_option( 'feature_6_text_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Feature 6 Link</label>';
												echo '<input type="text" name="feature_6_link" class="input_box" value="'.get_option( 'feature_6_link_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
										break; // END case 'features'
										
										case 'blog':
											$enable_blog = get_option( 'enable_blog_'.$fp_element->parent_id );
											echo '<div class="row clearfix alternate">';
												echo '<label>Enable Blog</label>';
												echo '<select name="enable_blog">';
													echo '<option value="yes"'; if ($enable_blog == 'yes') echo ' selected="selected"'; echo '>Yes</option>';
													echo '<option value="no"'; if ($enable_blog == 'no') echo ' selected="selected"'; echo '>No</option>';
												echo '</select>';
											echo '</div>';
											
											$blog_width = get_option( 'blog_width_'.$fp_element->parent_id );
											echo '<div class="row clearfix">';
												echo '<label>Blog Width</label>';
												echo '<select name="blog_width">';
													echo '<option value="1"'; if ($blog_width == '1') echo ' selected="selected"'; echo '>Full</option>';
													echo '<option value="0.5"'; if ($blog_width == '0.5') echo ' selected="selected"'; echo '>Half</option>';
												echo '</select>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Blog Heading</label>';
												echo '<input type="text" name="blog_heading" class="input_box" value="'.get_option( 'blog_heading_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											$current_categories = explode(',', get_option( 'blog_categories_'.$fp_element->parent_id ));
											$categories = get_categories();
											
											echo '<div class="row clearfix">';
												echo '<label>Blog Categories</label>';
												echo '<ul class="categories_listing">';								
													foreach ($categories as $category)
													{
														$validate = NULL;
														$checked = '';
														
														$haystack = array();
														$haystack[] = $category->cat_ID;
														
														foreach($current_categories as $current_category)
														{
															if ($current_category == $category->cat_ID)
															{
																$validate = true;
																break;
															}
														}

														if ( $validate != '' ) $checked = ' checked="checked"';
														echo '<li>';
															echo '<input id="post_'.$category->cat_ID.'" type="checkbox" name="blog_categories[]" value="'.$category->cat_ID.'"'.$checked.' />';
															echo $category->name;
														echo '</li>';										
													}
												echo '</ul>';	
											echo '</div>';
											
											$blog_elements_per_row = get_option( 'blog_elements_per_row_'.$fp_element->parent_id );
											echo '<div class="row clearfix alternate">';
												echo '<label>Elements per row ( full width only )</label>';
												echo '<select name="blog_elements_per_row">';
													echo '<option value="4"'; if ($blog_elements_per_row == '4') echo ' selected="selected"'; echo '>4 elements</option>';
													echo '<option value="3"'; if ($blog_elements_per_row == '3') echo ' selected="selected"'; echo '>3 elements</option>';
												echo '</select>';
											echo '</div>';
											
											echo '<div class="row clearfix">';
												echo '<label>Blog Count</label>';
												echo '<input type="text" name="blog_count" class="input_box" value="'.get_option( 'blog_count_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
										break; // END case 'blog'
										
										case 'slideshow':
											$enable_slideshow = get_option( 'enable_slideshow_'.$fp_element->parent_id );
											echo '<div class="row clearfix alternate">';
												echo '<label>Enable Slideshow</label>';
												echo '<select name="enable_slideshow">';
													echo '<option value="yes"'; if ($enable_slideshow == 'yes') echo ' selected="selected"'; echo '>Yes</option>';
													echo '<option value="no"'; if ($enable_slideshow == 'no') echo ' selected="selected"'; echo '>No</option>';
												echo '</select>';
											echo '</div>';
											
											$slideshow_width = get_option( 'slideshow_width_'.$fp_element->parent_id );
											echo '<div class="row clearfix">';
												echo '<label>Slideshow Width</label>';
												echo '<select name="slideshow_width">';
													echo '<option value="1"'; if ($slideshow_width == '1') echo ' selected="selected"'; echo '>Full</option>';
													echo '<option value="0.5"'; if ($slideshow_width == '0.5') echo ' selected="selected"'; echo '>Half</option>';
												echo '</select>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Slideshow Height</label>';
												echo '<input type="text" name="slideshow_height" class="input_box" value="'.get_option( 'slideshow_height_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix">';
												echo '<label>Slideshow Heading</label>';
												echo '<input type="text" name="slideshow_heading" class="input_box" value="'.get_option( 'slideshow_heading_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Slideshow Description</label>';
												echo '<textarea rows="8" cols="200;" name="slideshow_description" class="input_box">';
													echo get_option( 'slideshow_description_'.$fp_element->parent_id );
												echo '</textarea>';
											echo '</div>';
											
											$slideshow_transitions = get_option( 'slideshow_transitions_'.$fp_element->parent_id );
											echo '<div class="row clearfix">';
												echo '<label>Slideshow Transitions</label>';
												echo '<select name="slideshow_transitions">';
													echo '<option value="sliceDown"';          if ($slideshow_transitions == 'sliceDown')          echo ' selected="selected"'; echo '>SliceDown</option>';
													echo '<option value="sliceDownLeft"';      if ($slideshow_transitions == 'sliceDownLeft')      echo ' selected="selected"'; echo '>SliceDownLeft</option>';
													echo '<option value="sliceUp"';            if ($slideshow_transitions == 'sliceUp')            echo ' selected="selected"'; echo '>SliceUp</option>';
													echo '<option value="sliceUpLeft"';        if ($slideshow_transitions == 'sliceUpLeft')        echo ' selected="selected"'; echo '>SliceUpLeft</option>';
													echo '<option value="sliceUpDown"';        if ($slideshow_transitions == 'sliceUpDown')        echo ' selected="selected"'; echo '>SliceUpDown</option>';
													echo '<option value="sliceUpDownLeft"';    if ($slideshow_transitions == 'sliceUpDownLeft')    echo ' selected="selected"'; echo '>SliceUpDownLeft</option>';
													echo '<option value="fold"';               if ($slideshow_transitions == 'fold')               echo ' selected="selected"'; echo '>Fold</option>';
													echo '<option value="fade"';               if ($slideshow_transitions == 'fade')               echo ' selected="selected"'; echo '>Fade</option>';
													echo '<option value="random"';             if ($slideshow_transitions == 'random')             echo ' selected="selected"'; echo '>Random</option>';
													echo '<option value="slideInRight"';       if ($slideshow_transitions == 'slideInRight')       echo ' selected="selected"'; echo '>SlideInRight</option>';
													echo '<option value="slideInLeft"';        if ($slideshow_transitions == 'slideInLeft')        echo ' selected="selected"'; echo '>SlideInLeft</option>';
													echo '<option value="boxRandom"';          if ($slideshow_transitions == 'boxRandom')          echo ' selected="selected"'; echo '>BoxRandom</option>';
													echo '<option value="boxRain"';            if ($slideshow_transitions == 'boxRain')            echo ' selected="selected"'; echo '>BoxRain</option>';
													echo '<option value="boxRainReverse"';     if ($slideshow_transitions == 'boxRainReverse')     echo ' selected="selected"'; echo '>BoxRainReverse</option>';
													echo '<option value="boxRainGrow"';        if ($slideshow_transitions == 'boxRainGrow')        echo ' selected="selected"'; echo '>BoxRainGrow</option>';
													echo '<option value="boxRainGrowReverse"'; if ($slideshow_transitions == 'boxRainGrowReverse') echo ' selected="selected"'; echo '>BoxRainGrowReverse</option>';
												echo '</select>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Slideshow Pause Time</label>';
												echo '<input type="text" name="slideshow_pausetime" class="input_box" value="'.get_option( 'slideshow_pausetime_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
																						
											$current_categories = explode(',', get_option( 'slideshow_categories_'.$fp_element->parent_id ));
											$categories = get_categories();
											
											echo '<div class="row clearfix">';
												echo '<label>Slideshow Categories</label>';
												echo '<ul class="categories_listing">';								
													foreach ($categories as $category)
													{
														$validate = NULL;
														$checked = '';
														
														$haystack = array();
														$haystack[] = $category->cat_ID;
														
														foreach($current_categories as $current_category)
														{
															if ($current_category == $category->cat_ID)
															{
																$validate = true;
																break;
															}
														}

														if ( $validate != '' ) $checked = ' checked="checked"';
														echo '<li>';
															echo '<input id="post_'.$category->cat_ID.'" type="checkbox" name="slideshow_categories[]" value="'.$category->cat_ID.'"'.$checked.' />';
															echo $category->name;
														echo '</li>';										
													}
												echo '</ul>';	
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Slides Count</label>';
												echo '<input type="text" name="slideshow_count" class="input_box" value="'.get_option( 'slideshow_count_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
										break; // END case 'slideshow'
										
										case 'news':
											$enable_news = get_option( 'enable_news_'.$fp_element->parent_id );
											echo '<div class="row clearfix alternate">';
												echo '<label>Enable News</label>';
												echo '<select name="enable_news">';
													echo '<option value="yes"'; if ($enable_news == 'yes') echo ' selected="selected"'; echo '>Yes</option>';
													echo '<option value="no"'; if ($enable_news == 'no') echo ' selected="selected"'; echo '>No</option>';
												echo '</select>';
											echo '</div>';
											
											$news_width = get_option( 'news_width_'.$fp_element->parent_id );
											echo '<div class="row clearfix">';
												echo '<label>News Width</label>';
												echo '<select name="news_width">';
													echo '<option value="1"'; if ($news_width == '1') echo ' selected="selected"'; echo '>Full</option>';
													echo '<option value="0.5"'; if ($news_width == '0.5') echo ' selected="selected"'; echo '>Half</option>';
												echo '</select>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>News Heading</label>';
												echo '<input type="text" name="news_heading" class="input_box" value="'.get_option( 'news_heading_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											$current_categories = explode(',', get_option( 'news_categories_'.$fp_element->parent_id ));
											$categories = get_categories();
											
											echo '<div class="row clearfix">';
												echo '<label>News Categories</label>';
												echo '<ul class="categories_listing">';								
													foreach ($categories as $category)
													{
														$validate = NULL;
														$checked = '';
														
														$haystack = array();
														$haystack[] = $category->cat_ID;
														
														foreach($current_categories as $current_category)
														{
															if ($current_category == $category->cat_ID)
															{
																$validate = true;
																break;
															}
														}

														if ( $validate != '' ) $checked = ' checked="checked"';
														echo '<li>';
															echo '<input id="post_'.$category->cat_ID.'" type="checkbox" name="news_categories[]" value="'.$category->cat_ID.'"'.$checked.' />';
															// cred ca va trebui schimbat cat id
															//echo '<label for="scroller-category-'.$category->cat_ID.'">'.
															echo $category->name;
														echo '</li>';										
													}
												echo '</ul>';	
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>News Count</label>';
												echo '<input type="text" name="news_count" class="input_box" value="'.get_option( 'news_count_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
										break; // END case 'news'
										
										case 'tabs':
											$enable_tabs = get_option( 'enable_tabs_'.$fp_element->parent_id );
											echo '<div class="row clearfix alternate">';
												echo '<label>Enable Tabs</label>';
												echo '<select name="enable_tabs">';
													echo '<option value="yes"'; if ($enable_tabs == 'yes') echo ' selected="selected"'; echo '>Yes</option>';
													echo '<option value="no"'; if ($enable_tabs == 'no') echo ' selected="selected"'; echo '>No</option>';
												echo '</select>';
											echo '</div>';
											
											$tabs_width = get_option( 'tabs_width_'.$fp_element->parent_id );
											echo '<div class="row clearfix">';
												echo '<label>Tabs Width</label>';
												echo '<select name="tabs_width">';
													echo '<option value="1"'; if ($tabs_width == '1') echo ' selected="selected"'; echo '>Full</option>';
													echo '<option value="0.5"'; if ($tabs_width == '0.5') echo ' selected="selected"'; echo '>Half</option>';
												echo '</select>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Tabs Heading</label>';
												echo '<input type="text" name="tabs_heading" class="input_box" value="'.get_option( 'tabs_heading_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix">';
												echo '<label>Tab 1 Title</label>';
												echo '<input type="text" name="tab_1_title" class="input_box" value="'.get_option( 'tab_1_title_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Tab 1 Content</label>';
												echo '<textarea rows="8" cols="200;" name="tab_1_content" class="input_box">';
													echo get_option( 'tab_1_content_'.$fp_element->parent_id );
												echo '</textarea>';
											echo '</div>';
											
											echo '<div class="row clearfix">';
												echo '<label>Tab 2 Title</label>';
												echo '<input type="text" name="tab_2_title" class="input_box" value="'.get_option( 'tab_2_title_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Tab 2 Content</label>';
												echo '<textarea rows="8" cols="200;" name="tab_2_content" class="input_box">';
													echo get_option( 'tab_2_content_'.$fp_element->parent_id );
												echo '</textarea>';
											echo '</div>';
											
											echo '<div class="row clearfix">';
												echo '<label>Tab 3 Title</label>';
												echo '<input type="text" name="tab_3_title" class="input_box" value="'.get_option( 'tab_3_title_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Tab 3 Content</label>';
												echo '<textarea rows="8" cols="200;" name="tab_3_content" class="input_box">';
													echo get_option( 'tab_3_content_'.$fp_element->parent_id );
												echo '</textarea>';
											echo '</div>';
											
											echo '<div class="row clearfix">';
												echo '<label>Tab 4 Title</label>';
												echo '<input type="text" name="tab_4_title" class="input_box" value="'.get_option( 'tab_4_title_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Tab 4 Content</label>';
												echo '<textarea rows="8" cols="200;" name="tab_4_content" class="input_box">';
													echo get_option( 'tab_4_content_'.$fp_element->parent_id );
												echo '</textarea>';
											echo '</div>';
										break; // END case 'tabs'
										
										case 'testimonials':
											$enable_testimonials = get_option( 'enable_testimonials_'.$fp_element->parent_id );
											echo '<div class="row clearfix alternate">';
												echo '<label>Enable Testimonials</label>';
												echo '<select name="enable_testimonials">';
													echo '<option value="yes"'; if ($enable_testimonials == 'yes') echo ' selected="selected"'; echo '>Yes</option>';
													echo '<option value="no"'; if ($enable_testimonials == 'no') echo ' selected="selected"'; echo '>No</option>';
												echo '</select>';
											echo '</div>';
											
											$testimonials_width = get_option( 'testimonials_width_'.$fp_element->parent_id );
											echo '<div class="row clearfix">';
												echo '<label>Testimonials Width</label>';
												echo '<select name="testimonials_width">';
													echo '<option value="1"'; if ($testimonials_width == '1') echo ' selected="selected"'; echo '>Full</option>';
													echo '<option value="0.5"'; if ($testimonials_width == '0.5') echo ' selected="selected"'; echo '>Half</option>';
												echo '</select>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Testimonials Heading</label>';
												echo '<input type="text" name="testimonials_heading" class="input_box" value="'.get_option( 'testimonials_heading_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix">';
												echo '<label>Testimonial 1 Text</label>';
												echo '<textarea rows="8" cols="200;" name="testimonial_1_text" class="input_box">';
													echo get_option( 'testimonial_1_text_'.$fp_element->parent_id );
												echo '</textarea>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Testimonial 1 Person</label>';
												echo '<input type="text" name="testimonial_1_person" class="input_box" value="'.get_option( 'testimonial_1_person_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix">';
												echo '<label>Testimonial 1 Link</label>';
												echo '<input type="text" name="testimonial_1_link" class="input_box" value="'.get_option( 'testimonial_1_link_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Testimonial 2 Text</label>';
												echo '<textarea rows="8" cols="200;" name="testimonial_2_text" class="input_box">';
													echo get_option( 'testimonial_2_text_'.$fp_element->parent_id );
												echo '</textarea>';
											echo '</div>';
											
											echo '<div class="row clearfix">';
												echo '<label>Testimonial 2 Person</label>';
												echo '<input type="text" name="testimonial_2_person" class="input_box" value="'.get_option( 'testimonial_2_person_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Testimonial 2 Link</label>';
												echo '<input type="text" name="testimonial_2_link" class="input_box" value="'.get_option( 'testimonial_2_link_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix">';
												echo '<label>Testimonial 3 Text</label>';
												echo '<textarea rows="8" cols="200;" name="testimonial_3_text" class="input_box">';
													echo get_option( 'testimonial_3_text_'.$fp_element->parent_id );
												echo '</textarea>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Testimonial 3 Person</label>';
												echo '<input type="text" name="testimonial_3_person" class="input_box" value="'.get_option( 'testimonial_3_person_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix">';
												echo '<label>Testimonial 3 Link</label>';
												echo '<input type="text" name="testimonial_3_link" class="input_box" value="'.get_option( 'testimonial_3_link_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
										break; // END case 'testimonials'
										
										case 'contact':
											$enable_contact = get_option( 'enable_contact_'.$fp_element->parent_id );
											echo '<div class="row clearfix alternate">';
												echo '<label>Enable Contact Form</label>';
												echo '<select name="enable_contact">';
													echo '<option value="yes"'; if ($enable_contact == 'yes') echo ' selected="selected"'; echo '>Yes</option>';
													echo '<option value="no"'; if ($enable_contact == 'no') echo ' selected="selected"'; echo '>No</option>';
												echo '</select>';
											echo '</div>';
											
											echo '<div class="row clearfix">';
												echo '<label>Contact Heading</label>';
												echo '<input type="text" name="contact_heading" class="input_box" value="'.get_option( 'contact_heading_'.$fp_element->parent_id ).'" size="100"/>';
											echo '</div>';
											
											$enable_recaptcha = get_option( 'enable_recaptcha_'.$fp_element->parent_id );
											echo '<div class="row clearfix alternate">';
												echo '<label>Enable reCaptcha</label>';
												echo '<select name="enable_recaptcha">';
													echo '<option value="yes"'; if ($enable_recaptcha == 'yes') echo ' selected="selected"'; echo '>Yes</option>';
													echo '<option value="no"'; if ($enable_recaptcha == 'no') echo ' selected="selected"'; echo '>No</option>';
												echo '</select>';
											echo '</div>';
										break; // END case 'contact'
										
										case 'custom':
											$enable_custom = get_option( 'enable_custom_'.$fp_element->parent_id );
											echo '<div class="row clearfix alternate">';
												echo '<label>Enable Custom Element</label>';
												echo '<select name="enable_custom">';
													echo '<option value="yes"'; if ($enable_custom == 'yes') echo ' selected="selected"'; echo '>Yes</option>';
													echo '<option value="no"'; if ($enable_custom == 'no') echo ' selected="selected"'; echo '>No</option>';
												echo '</select>';
											echo '</div>';
											
											$custom_width = get_option( 'custom_width_'.$fp_element->parent_id );
											echo '<div class="row clearfix">';
												echo '<label>Custom Width</label>';
												echo '<select name="custom_width">';
													echo '<option value="1"'; if ($custom_width == '1') echo ' selected="selected"'; echo '>Full</option>';
													echo '<option value="0.5"'; if ($custom_width == '0.5') echo ' selected="selected"'; echo '>Half</option>';
												echo '</select>';
											echo '</div>';
											
											echo '<div class="row clearfix alternate">';
												echo '<label>Custom Element Heading</label>';
												echo '<input type="text" name="custom_heading" class="input_box" value="'.get_option( 'custom_heading_'.$fp_element->parent_id ).'" size="20"/>';
											echo '</div>';
											
											echo '<div class="row clearfix">';
												echo '<label>Custom Element Content</label>';
												echo '<textarea rows="14" cols="200;" name="custom_content" class="input_box">';
													echo get_option( 'custom_content_'.$fp_element->parent_id );
												echo '</textarea>';
											echo '</div>';
										break; // END case 'custom'
										
										case 'the_content':
											$enable_the_content = get_option( 'enable_the_content_'.$fp_element->parent_id );
											echo '<div class="row clearfix alternate">';
												echo '<label>Enable The Page Content</label>';
												echo '<select name="enable_the_content">';
													echo '<option value="yes"'; if ($enable_the_content == 'yes') echo ' selected="selected"'; echo '>Yes</option>';
													echo '<option value="no"'; if ($enable_the_content == 'no') echo ' selected="selected"'; echo '>No</option>';
												echo '</select>';
											echo '</div>';
											
											$display_the_content_title = get_option( 'display_the_content_title_'.$fp_element->parent_id );
											echo '<div class="row clearfix alternate">';
												echo '<label>Display The Page Content Title</label>';
												echo '<select name="display_the_content_title">';
													echo '<option value="yes"'; if ($display_the_content_title == 'yes') echo ' selected="selected"'; echo '>Yes</option>';
													echo '<option value="no"'; if ($display_the_content_title == 'no') echo ' selected="selected"'; echo '>No</option>';
												echo '</select>';
											echo '</div>';
											
											$the_content_width = get_option( 'the_content_width_'.$fp_element->parent_id );
											echo '<div class="row clearfix">';
												echo '<label>The Content Width</label>';
												echo '<select name="the_content_width">';
													echo '<option value="1"'; if ($the_content_width == '1') echo ' selected="selected"'; echo '>Full</option>';
													echo '<option value="0.5"'; if ($the_content_width == '0.5') echo ' selected="selected"'; echo '>Half</option>';
												echo '</select>';
											echo '</div>';
										break; // END case 'the_content'
										
									} // END switch($fp_element->type)
									

									echo '</div>';

								echo '</li>';
								
							} // END foreach ($display_fp_elements as $fp_element)
							
							
							echo '</ul>';
							echo '<input class="save_button" type="submit" value="Save changes" name="search">';
						echo '</form>';
					echo '</div>';
					

				} // END foreach ($front_page_id_list as $key => $front_page_id)
			
			echo '</div>'; // <div id="tabs"> 
			
		?>
        
</div> <!-- END  .wrap  -->

<?php
	}  // END front_page_admin_page()
?>